2 Ways to Convert a String to an Array in Power Automate 您所在的位置:网站首页 2 Ways to Attach Files to an Email in Power Automate 2 Ways to Convert a String to an Array in Power Automate

2 Ways to Convert a String to an Array in Power Automate

2024-06-02 05:39| 来源: 网络整理| 查看: 265

Do you need to turn a text value into an array of items?

Your data might come into the flow as a list in a single text value, but you need to act on each item individually. This means you will need to convert the text into an array!

This post will show you how to convert a string into an array in Power Automate.

Convert a String to an Array with the SPLIT Function

The split function will allow you to split text based on a delimiter value.

This is a great option for a string such as a comma-separated list and will allow you to get each item between the commas.

You can use the split function to split your text into an array based on the delimiter such as a comma.

John, Mark, Jen

This example shows a list of names separated by a comma and a space character.

split(outputs('String'),', ')

The above expression will split the string value of names from the compose action based on the comma and space characters ', '. This returns an array with each individual name as an element of the array.

[ "John", "Mark", "Jen" ]

When this runs, the function returns the above array of 3 names.

Convert a String to an Array with the CHUNK Function

The split is excellent when you have a delimited string value. But what options do you have when there is no delimiter in your text?

The chunk function allows you to split text based on character length. It will separate a text value into equal-length parts based on a given number of characters.

This example shows a ten character long string.

chunk(outputs('String'),3)

The above expression will split the string value into equal sections of 3 characters.

In this example, the input string is 10 characters and it’s being split into sections of 3 characters long. This will result in three array elements of 3 characters each plus one array element of 1 character.

[ "ABC", "123", "TPS", "3" ]

When the flow runs, it will result in the above array.

Conclusions

Comma-separated lists and other delimited text data are a common occurrence and you may need to convert these into arrays in your flow to properly deal with them.

The split function offers a simple solution for separating any delimited string into an array.

The chunk function is also another option to turn a string into an array when no delimiters are present. This will split based on a chosen character length instead.

Have you come across the need to convert a string into an array? How did you get this done? Let me know in the comments below!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有